//
//  HZOrderHeaderViewModel.m
//  app
//
//  Created by 刘华舟 on 15/5/6.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZOrderHeaderViewModel.h"

@implementation HZOrderHeaderViewModel

+ (instancetype)modelWithDictionary:(NSDictionary *)dict{
    return [[HZOrderHeaderViewModel alloc] initWithDictionary:dict];
}
- (instancetype)initWithDictionary:(NSDictionary *)dict{
    if (self = [super init]) {
        _originalMoney = @"0.00";
        self.totalMoney = [dict stringForKey:APIKEY_mall_total_prices nilValue:@"0.00"];
        self.transformMoney = [dict stringForKey:APIKEY_mall_postage nilValue:@"0.00"];
        NSInteger userTotal = [[dict stringForKey:APIKEY_mall_userTotal nilValue:@"0"] integerValue];
        NSInteger orderTotal = [[dict stringForKey:APIKEY_mall_orderTotal nilValue:@"0"] integerValue];
        
        //最多可使用的金豆
        NSInteger maxGold = userTotal > orderTotal ? orderTotal:userTotal;
        CGFloat goldMoney = [[dict stringForKey:APIKEY_mall_1gold2RMB nilValue:@"0.00"] floatValue];
        
        maxGold = [self.totalMoney floatValue]/goldMoney < maxGold ? [self.totalMoney floatValue]/goldMoney : maxGold;
        
        self.goldBeansMoney = [NSString stringWithFormat:@"%0.2f", maxGold*goldMoney];
        
        
        
        self.useGoldBeans = YES;
        self.avalibleGoldBeansNum = [NSString stringWithFormat:@"%d", maxGold];
        self.checkMoney = [NSString stringWithFormat:@"%0.2f",[self.totalMoney floatValue]+[self.transformMoney floatValue]];
    }
    return self;
}

@end
